   Rem	VBScript For probing In the x+ direction With tool diameter Input Metric Version


CurrentFeed = GetOemDRO(818) 'Get the current feedrate to return to later
CurrentAbsInc = GetOemLED(48) 'Get the current G90/G91 state
CurrentGmode = GetOemDRO(819) 'Get the current G0/G1 state
CurrentToolDiameter = GetOemDRO(43) 'gets the current tool diameter

If GetOemLed (825) <> 0 Then 		'Check to see if the probe is already grounded or faulty
	Call ProbeGrounded()
	Exit Sub
Else
	Code "G4 P2"			'Pause 1 second to give time to position probe plate
	Code "F100"

Rem	Probe Right

	XNew = GetDro(0) + 75	'probe to current position - 75mm
	Code "G31 X" &XNew
	While IsMoving()		'wait for prob move to complete
	Wend
	XNew = GetVar(2000)		'read the touch point

Rem	move back To the hit point incase there was an overshoot

	Code "G91 G0 Z15"
	Code "G90 G0 X" &XNew
	Code "G91 X" &CurrentToolDiameter/2  'moves the probe half the tool diameter to center on edge
        
	
	While IsMoving ()
	Wend
        Call SetDro (0,0.000)
        Code "G4 P0.25" 

	Code "F" &CurrentFeed 		'restore original feed rate
	Call ReturnG90G91State()
	Exit Sub
End If
 
Sub ProbeGrounded()
	Code "(Probe plate is grounded, check connection and try again)"
	Call ReturnG90G91State()
End Sub

Sub ReturnG90G91State()
	If CurrentAbsInc = 0 Then 'if G91 was in effect before then return to it
		Code "G91"
	End If
	If CurrentGMode = 0 Then 'if G0 was in effect before then return to it
		Code "G0"
	End If
End Sub    
 
  
